<?php
session_start();
include "Includes/solotrn_sesion.php";
include "Includes/soloFun_Generales.php";
require_once "config.php";
require_once "Includes/conexion.class.php";

$txtId = $_REQUEST["id"];
$nombre = $_REQUEST["nombre"];
$strsql = "SELECT archivo1 FROM solotb_ticket WHERE id = $txtId";
$archivo = SoloFun_ExecSql($strsql, $arr);

$file = fopen($nombre, "wb");
if (!is_resource($file))
{
    die("Cannot open $nombre");
}

fwrite($file, $archivo);
fclose($file);

//First, see if the file exists
    if (!is_file($file)) { die("<b>404 File not found!</b>"); }
    $ctype = "application/msword";
    //Gather relevent info about file
    $len = filesize($file);
    $filename = basename($file);
    $file_extension = strtolower(substr(strrchr($filename,"."),1));


//Begin writing headers
    header("Pragma: public");
    header("Expires: 0");
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    header("Cache-Control: public");
    header("Content-Description: File Transfer");

    //Use the switch-generated Content-Type
    header("Content-Type: $ctype");

    //Force the download
    $header="Content-Disposition: attachment; filename=".$filename.";";
    header($header );
    header("Content-Transfer-Encoding: binary");
    header("Content-Length: ".$len);
    @readfile($file);
    exit;
?>
